import promptAction from '@ohos.promptAction';
import Logger from './Logger'
let TAG = "_:[promptMgr]"
export default class toastManager {
  extra = ""

  constructor() {
    console.error("_: toastManager constructed")
  }
  Toast(message, duration = 2000) {
    message += "\n\nEXTRA:" + this.extra
    console.log(TAG, "_:onChange", "toasting", message.replace(/\n/g, ""), duration)
    this.extra = ""
    promptAction.showToast({
      message: message,
      duration: duration
    });
  }
  Dialog({ title, message, buttons }) {
    console.log(TAG, "[toasting]", title, message)
    console.log(TAG, "[        ]", JSON.stringify(buttons))
    promptAction.showDialog({
      title: title,
      message: message,
      buttons: buttons,
    }).then(data => {
      console.log(TAG, 'dialog success callback, click button : ' + data.index + JSON.stringify(buttons[data.index]));
    })
      .catch((err: Error) => {
        console.log(TAG, 'dialog cancel callback');
      })
  }
}
